﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private static bool couldRun = true;
        private void Form1_Load(object sender, EventArgs e)
        {
            this.Width = 960;
            this.Height = 600;


        }

        private void webBrowser1_DocumentCompleted1(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            var username = webBrowser1.Document.All["TextBox1"];
            var password = webBrowser1.Document.All["TextBox2"];
            var button = webBrowser1.Document.All["ImageButton1"];
            if (username != null && password != null)
            {
                username.SetAttribute("value", "admin");
                password.SetAttribute("value", "admin");

                button.InvokeMember("click");
                couldRun=true;

            }
            //FindNextStepUrl(1);
        }


        private void FindNextStepUrl(int stepId)
        {
            if (couldRun)
            {
                couldRun = false;
                string url = "http://180.168.163.198:90/";
                DoMyTests(url);
            }
        }

        private void DoMyTests(string url)
        {
            this.webBrowser1.Navigate(url);
            this.webBrowser1.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(this.webBrowser1_DocumentCompleted1);

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            FindNextStepUrl(1);
        }


    }
}
